﻿// Copyright (c)  YISH. All rights reserved.
// Licensed under the MIT License, See License.txt in the project root for license information.

using NSQL.Sharpen;

namespace NSQL.Expressions.Functions
{
    public class TrimFunction : BaseExpression, ITrimFunction
    {
        public IStringExpression Expr { get; set; }
        public IConstantStringExpression TrimExpr { get; set; }
        public TrimType Type { get; set; }

        public TrimFunction(IExpression expression, TrimType type = TrimType.Both)
        {
            Expr = (IStringExpression) expression;
            Type = type;
        }
        public TrimFunction(IExpression expression, IConstantStringExpression trim , TrimType type = TrimType.Both)
        {
            Expr = (IStringExpression) expression;
            TrimExpr = trim;
            Type = type;
        }

        public override T Accept<T>(IExpressionVisitor<T> visitor) => visitor.Visit(this);
        public override void Accept(IExpressionVisitor visitor) => visitor.Visit(this);
        public override bool IsValid => Expr.IsValid && TrimExpr.IsValid;
        protected override IExpression DeepCopy()
        {
            return new TrimFunction(Expr.DeepClone(), TrimExpr.DeepClone(), Type)
            {
                Tag = Tag
            };
        }
    }
}